using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlyingPointsController : MonoBehaviour
{
	public static FlyingPointsController instance;

	public FlyingPoints flyingPointsPrefab;

	[HideInInspector]
	public Vector3 screenCenter = new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f);

	[HideInInspector]
	public Camera mainCamera;

	[HideInInspector]
	public UIRoot uiRoot;

	public FlyingPointsInfo CashFlyingPointsInfo;

	public FlyingPointsInfo GoldFlyingPointsInfo;

	public FlyingPointsInfo HealtsFlyingPointsInfo;

	public FlyingPointsInfo AmmoFlyingPointsInfo;

	public FlyingPointsInfo ReputationFlyingPointsInfo;

	public FlyingPointsInfo JetpackFlyingPointsInfo;

	public FlyingPointsInfo StarsFlyingPointsInfo;

	private void Awake()
	{
		instance = this;
		mainCamera = Camera.main;
	}

	public void AddFlyingPoints(FlyingPointsInfo flyingPointsInfo, Vector3 origin, Vector3 destination, bool worldToGUI, IEnumerator callBack)
	{
		FlyingPoints flyingPoints = Object.Instantiate(flyingPointsPrefab);
		flyingPoints.transform.SetParent(base.gameObject.transform);
		flyingPoints.transform.localScale = Vector3.one;
		flyingPoints.Init(flyingPointsInfo, origin, destination, worldToGUI, callBack);
	}

	public void AddFlyingPoints(Vector3 origin, PointsType pointsType, int amount, bool worldToGUI, IEnumerator callBack = null)
	{
		FlyingPointsInfo flyingPointsInfo = default(FlyingPointsInfo);
		Vector3 destination = Vector3.zero;
		switch (pointsType)
		{
		case PointsType.Cash:
			flyingPointsInfo = CashFlyingPointsInfo;
			destination = MoneyPanel.instance.dollar.transform.position;
			break;
		case PointsType.Gold:
			flyingPointsInfo = GoldFlyingPointsInfo;
			destination = MoneyPanel.instance.gold.transform.position;
			break;
		case PointsType.Healts:
			flyingPointsInfo = HealtsFlyingPointsInfo;
			destination = GameTopWindow.instance.healtsIcon.transform.position;
			callBack = GameTopWindow.instance.BonusAnimation(GameTopWindow.instance.healtsIcon);
			break;
		case PointsType.Ammo:
		{
			flyingPointsInfo = AmmoFlyingPointsInfo;
			if (GameController.instance.playerScript.inCar)
			{
				destination = CarWindow.instance.labelBullet.transform.position;
				callBack = GameTopWindow.instance.BonusAnimation(CarWindow.instance.labelBullet);
				break;
			}
			if (GameController.instance.playerScript.inHelic)
			{
				destination = FlyWindow.instance.labelBullet.transform.position;
				callBack = GameTopWindow.instance.BonusAnimation(FlyWindow.instance.labelBullet);
				break;
			}
			destination = WalkWindow.instance.slotSelector.transform.position;
			List<GameObject> list = new List<GameObject>();
			list.Add(WalkWindow.instance.slotSelector.sellectorTexture.gameObject);
			list.Add(WalkWindow.instance.slotSelector.label.gameObject);
			callBack = GameTopWindow.instance.BonusAnimation(list);
			break;
		}
		case PointsType.Reputation:
			flyingPointsInfo = ReputationFlyingPointsInfo;
			destination = GameReputationUI.instance.reputationHolder.transform.position;
			break;
		case PointsType.Jetpack:
			flyingPointsInfo = JetpackFlyingPointsInfo;
			destination = WalkWindow.instance.fuelJetpack.transform.position;
			callBack = GameTopWindow.instance.BonusAnimation(WalkWindow.instance.fuelJetpack.gameObject);
			break;
		case PointsType.Stars:
			flyingPointsInfo = StarsFlyingPointsInfo;
			destination = GameReputationUI.instance.cupsCount.transform.position;
			break;
		}
		AddFlyingPoints(flyingPointsInfo, origin, destination, worldToGUI, callBack);
	}

	public void AddFlyingPointsByAmount(Vector3 origin, PointsType pointsType, int amount, bool worldToGUI)
	{
		if (base.gameObject.activeInHierarchy)
		{
			StartCoroutine(AddFlyingPointsByAmountCorutine(origin, pointsType, amount, worldToGUI));
		}
	}

	private IEnumerator AddFlyingPointsByAmountCorutine(Vector3 origin, PointsType pointsType, int amount, bool worldToGUI)
	{
		if (pointsType == PointsType.Cash)
		{
			int hundreds = (int)Mathf.Floor(amount / 100);
			int dozens = (int)Mathf.Floor((amount - 100 * hundreds) / 10);
			int ones = (int)Mathf.Floor(amount - 100 * hundreds - 10 * dozens);
			FlyingPointsInfo flyingPointsInfo = CashFlyingPointsInfo;
			Vector3 destination = MoneyPanel.instance.dollar.transform.position;
			IEnumerator callBack = null;
			flyingPointsInfo.iconSpriteName = "Cash_animation_3";
			for (int k = 0; k < hundreds; k++)
			{
				AddFlyingPoints(flyingPointsInfo, origin, destination, worldToGUI, callBack);
				yield return StartCoroutine(CoroutineRunner.WaitForSeconds(0.1f));
			}
			flyingPointsInfo.iconSpriteName = "Cash_animation_2";
			for (int j = 0; j < dozens; j++)
			{
				AddFlyingPoints(flyingPointsInfo, origin, destination, worldToGUI, callBack);
				yield return StartCoroutine(CoroutineRunner.WaitForSeconds(0.1f));
			}
			flyingPointsInfo.iconSpriteName = "Cash_animation_1";
			for (int i = 0; i < ones; i++)
			{
				AddFlyingPoints(flyingPointsInfo, origin, destination, worldToGUI, callBack);
				yield return StartCoroutine(CoroutineRunner.WaitForSeconds(0.1f));
			}
		}
		else
		{
			for (int l = 1; l <= amount; l++)
			{
				AddFlyingPoints(origin, pointsType, 0, worldToGUI);
				yield return StartCoroutine(CoroutineRunner.WaitForSeconds(0.1f));
			}
		}
	}

	public void PlaySound(string clip, float volumeMultiplier)
	{
		if (!clip.Equals(string.Empty))
		{
			BCWAudioResource.Instance.PlaySound(clip, VolumeController.VolumeSound * volumeMultiplier, 1f);
		}
	}
}
